<?php
use \think\Route;
use \think\Config;

$routes = [
    '/about' => 'index/about',
    '/contact' => 'index/contact',
    '/terms' => 'index/terms',
    '/privacy' => 'index/privacy',
    '/list' => 'index/list',
    '/lyrics/:title' => 'index/detail',
    '/api/search' => 'api/search',
    '/api/like' => 'api/like',
    '/api/updateViews' => 'api/updateViews',
    '/api/updateDownloads' => 'api/updateDownloads',
    '/api/updatePrints' => 'api/updatePrints',
    '/' => 'index/index',
];

// 获取支持的语言列表
$lang_list = array_keys(Config::get('app.available_langs'));
$default_lang = Config::get('default_lang');
// 删除默认语言 
unset($lang_list[array_search($default_lang,$lang_list)]);

// 为每个语言创建路由组
// 例如: /en/about, /zh-cn/about 等
foreach ($lang_list as $lang) {
    // debug_dump($lang_url);
    Route::group($lang, function() use ($routes) {
        // 遍历基础路由规则,为每个语言创建对应的路由
        foreach ($routes as $rule => $route) {
            Route::rule($rule, $route);
        }
    });
}
foreach ($routes as $rule => $route) {
    Route::rule($rule, $route);
}


